package calvin.study.rabbitmq.advanced.limit;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import calvin.study.rabbitmq.base.RabbitMqBase;

public class Consumer2 extends RabbitMqBase {
	
	public static void main(String[] args) throws Exception {

		// 1 创建ConnectionFactory
		ConnectionFactory connectionFactory = getConnectionFactory();

		// 2 获取C onnection
		Connection connection = connectionFactory.newConnection();

		// 3 通过Connection创建一个新的Channel
		Channel channel = connection.createChannel();

		String exchangeName = "confirm_topic_exchange";
		String routingKey = "confirm.#";
		String queueName = "confirm_queue";

		// 4 声明交换机和队列 然后进行绑定设置, 最后制定路由Key
		channel.exchangeDeclare(exchangeName, "topic", true,false,null);
		channel.queueDeclare(queueName, true, false, false, null);
		channel.queueBind(queueName, exchangeName, routingKey);
		
		/**
		 * @param prefetchSize 消息本身的大小，如果设置为0，那么表示对消息本身大小不限制。
		 * @param prefetchCount 告诉mq不要一次性给消费者推送大于N个消息（这里配置为5）
		 * @param global true是将此配置应用于channnel级别 false 是将此配置应用于consumer级别
		 */
		//channel.basicQos(0, 5, false);
		
		channel.basicConsume(queueName, false, new CustomConsumer(channel));	
	}

}
